package com.rpay.admin.controller.file;
/**
 * @author XXX
 * @mail XXX@hotmail.com
 * @date 2018/5/9
 * @Description:后台文件上传模块
 */

import com.rpay.common.util.FileUtil;
import com.rpay.common.vo.PcsResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.rpay.common.dto.file.FileDTO;

import java.io.IOException;

@RestController
@RequestMapping(value = "noa/file")
@Validated
public class UploadController {
    @Value("${file.file.location}")
    private String location;
    @Value("${file.file.url}")
    private String imgUrl;

    @PostMapping(value = "/upload")
    public PcsResult upload(@RequestParam("file") MultipartFile file) {
        String fileUrl = null;
        try {
            fileUrl = FileUtil.upload(location, imgUrl, file);
        } catch (IOException e) {
        }
        FileDTO fileDTO = new FileDTO();
        fileDTO.setUrl(fileUrl);
        return PcsResult.build(fileDTO);
    }
}
